package com.topInterview;

import java.util.Stack;

public class leecode150 {
    public int process(String[] str) {
        Stack<Integer> stack = new Stack<>();
        for (String s : str) {
            if (s.equals("+") || s.equals("-") || s.equals("*") || s.equals("/")) {
                stack.push(compute(s, stack));
            } else {
                stack.push(Integer.valueOf(s));
            }
        }
        return stack.peek();

    }


    public int compute(String str, Stack<Integer> stack) {
        int num2 = stack.pop();
        int num1 = stack.pop();
        switch (str) {
            case "+":
                return num1 + num2;
            case "-":
                return num1 - num2;
            case "*":
                return num1 * num2;
            case "/":
                return num1 / num2;
        }
        return 0;
    }
}
